package com.xunyji.rabbitmq01.producer;

import com.xunyji.rabbitmq01.entity.Order;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 王杨帅
 * @create 2018-08-30 19:58
 * @desc
 **/
@Component
public class OrderSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendOrder(Order order) throws Exception {

        CorrelationData correlationData = new CorrelationData();
        correlationData.setId(order.getMessageId());

        rabbitTemplate.convertAndSend(
                "order-exchange",
                "order.abcd",
                order, // 消息体内容
                correlationData // 消息唯一ID
        );

    }

}

